from scipy.io import loadmat
import os


def inspect_mat_file(file_path):
    """
    查看MAT文件中的内容
    :param file_path: MAT文件路径
    """
    mat_data = loadmat(file_path)
    print("Keys in the MAT file:")
    for key in mat_data.keys():
        if not key.startswith('__'):
            print(f"Key: {key}, Shape: {mat_data[key].shape if hasattr(mat_data[key], 'shape') else 'N/A'}")
            print(f"Value: {mat_data[key]}")
            print("-" * 50)


def inspect_specific_keys(file_path, keys):
    """
    查看MAT文件中特定键的内容
    :param file_path: MAT文件路径
    :param keys: 要查看的键列表
    """
    mat_data = loadmat(file_path)
    for key in keys:
        if key in mat_data:
            print(f"Key: {key}, Shape: {mat_data[key].shape if hasattr(mat_data[key], 'shape') else 'N/A'}")
            print(f"Value: {mat_data[key]}")
            print("-" * 50)
        else:
            print(f"Key '{key}' not found in the MAT file.")


def main():
    # 设置数据目录
    DATADIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data/")

    # Yelp数据集的MAT文件路径
    # yelp_file = os.path.join(DATADIR, 'Yelp.mat')
    yelp_file = os.path.join(DATADIR, 'Amazon.mat')

    # 查看MAT文件中的所有内容
    print("Inspecting all keys in the MAT file:")
    inspect_mat_file(yelp_file)

    # 查看特定键的内容
    keys_to_inspect = ['homo', 'net_rur', 'net_rtr', 'net_rsr']
    print("Inspecting specific keys:")
    inspect_specific_keys(yelp_file, keys_to_inspect)


if __name__ == "__main__":
    main()